<!-- 搜索表单 -->
<template>
  <ele-card :body-style="{ paddingBottom: '2px' }">
    <el-form label-width="72px" @keyup.enter="search" inline>
      <el-form-item label="所属公司">
        <TenantChoose @loaded="search" v-model="form.tenant_id" />
      </el-form-item>
      <br />
      <el-form-item label="状态">
        <el-radio-group v-model="form.type" @change="search">
          <el-radio-button label="all">全部</el-radio-button>
          <el-radio-button label="watingPay">待还款</el-radio-button>
          <el-radio-button label="clear">已还清</el-radio-button>
          <el-radio-button label="over">已逾期</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <!-- 自定义日期范围 -->
      <el-form-item label="预支日期">
        <el-date-picker
          v-model="dateRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="generateDates"
          value-format="YYYY-MM-DD"
          style="width: 300px"
        />
      </el-form-item>
      <br />
      <el-form-item label="姓名">
        <el-input v-model="form.realname" />
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="form.tel" />
      </el-form-item>
      <el-form-item label="身份证">
        <el-input v-model="form.identifier" />
      </el-form-item>

      <el-form-item label-width="16px">
        <el-button type="primary" @click="search">查询</el-button>
      </el-form-item>
    </el-form>
  </ele-card>
</template>

<script setup>
  import { ref } from 'vue';
  import { useFormData } from '@/utils/use-form-data';
  const emit = defineEmits(['search']);

  /** 表单数据 */
  const [form] = useFormData({
    wating_pay: 1,
    realname: '',
    tel: '',
    identifier: '',
    user_id: 0,
    type: 'all',
    end_date: '',
    start_date: '',
    judge_start_date: '',
    judge_end_date: ''
  });

  /** 工资日期范围 */
  const dateRange = ref([]);
  const generateDates = () => {
    if (!dateRange.value || dateRange.value.length !== 2) {
      form.start_date = '';
      form.end_date = '';
    } else {
      form.start_date = dateRange.value[0];
      form.end_date = dateRange.value[1];
    }
  };

  /** 搜索 */
  const search = () => {
    emit('search', { ...form });
  };
</script>
